package bme.andraskindler.treenventory.fragment;

import bme.andraskindler.treenventory.activity.MeasureActivity;
import bme.andraskindler.treenventory.activity.TreeTypeActivity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.Toast;

/**
 * A hátom leggyakoribb fatípust megjelenítő fragment, az új típus kreálására szolgáló {@link TreeTypeActivity} is innen indítható.
 * Szülője a {@link MeasureActivity}. 
 * @author andraskindler
 *
 */
public class TreeChooserDialogFragment extends DialogFragment {

	public TreeChooserDialogFragment() {
		super();
	}

	public static TreeChooserDialogFragment newInstance() {
		return new TreeChooserDialogFragment();
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		final String[] items = { "Tölgy", "Bükk", "Fenyő", "további típusok..." };

		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setTitle("Leggyakrabb típusok:");
		builder.setItems(items, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int item) {
				if (item == 3)
					startActivityForResult(new Intent(getActivity(), TreeTypeActivity.class), MeasureActivity.TYPE_RESULT);
				else {
					Toast.makeText(getActivity(), items[item] + " kiválasztva", Toast.LENGTH_SHORT).show();
					MeasureActivity.class.cast(getActivity()).setType(items[item]);
				}
			}
		});
		return builder.create();
	}

}
